﻿using Microsoft.VisualBasic.ApplicationServices;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TomatoClock.Models
{
    public class UserManager
    {
        public List<User> Users { get; set; }
        public UserManager() {
            Users = new List<User>();
            User user1 = new User { UserName = "user1", Password = "password1" };//测试
            Users.Add(user1);
        }
        public bool EnrollUser(string username, string password)
        {
            if (Users.Any(u => u.UserName == username))
            {
                return false;
            }
            return true;
        }
        public void AddUser(string username, string password) {
            Users.Add(new User { UserName = username, Password = password });
            return;
        }
        public bool LoginUser(string username, string password)
        {
            var user = Users.FirstOrDefault(u => u.UserName == username && u.Password == password);

            if (user == null)
            {
                return false;
            }
            return true;
        }
        //更新用户专注时间
        public void UpdateFocusTime(string username, int time)
        {
            var user = Users.FirstOrDefault(u => u.UserName == username);
            if (user != null)
            {
                user.data.FocusTime += time;
                user.data.FocusTimeWeekly += time;
                user.data.FocusTimeSum += time;
            }
        }

        // 更新用户完成任务数量
        public void UpdateTaskNum(string username, int count)
        {
            var user = Users.FirstOrDefault(u => u.UserName == username);
            if (user != null)
            {
                user.data.TaskNum += count;
                user.data.TaskNumWeekly += count;
                user.data.TaskNumSum += count;
            }
        }

        // 更新用户收成数量
        public void UpdateTomatoNum(string username, int count)
        {
            var user = Users.FirstOrDefault(u => u.UserName == username);
            if (user != null)
            {
                user.data.TomatoNum += count;
                user.data.TomatoNumWeekly += count;
                user.data.TomatoNumSum += count;
            }
        }
    }
}
